import { observable, action } from 'mobx'
import http from 'utils/http'

class LoginStore {
  @observable isLogin = false

  static sendCode(mobile) {
    http.get('user/sendCode', { mobile })
  }

  static async login(payload) {
    const res = await http.post('user/login', payload)
    if (res.code === 1) {
      return res.data
    }
    throw new Error(res.data)
  }

  @action
  async checkToken(token) {
    const res = await http.get('user/checkToken', { token })
    if (res.code === 1) {
      this.isLogin = true
    }
  }
}


const loginStore = new LoginStore()

export default loginStore
export { LoginStore }
